# -*- coding: utf-8 -*-

import pymysql
import time

db = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="root", db="test", charset="utf8")
cursor = db.cursor()

def mysql_checking(mobile_no):
    sql_demand = "SELECT 1 FROM dingding_all_info_spider WHERE mobile_no='" + mobile_no + "' LIMIT 1"

    demand = cursor.execute(sql_demand)
    db.commit()
    if demand > 0:
        print('联系方式已存在')
        return False
    else:
        return True
def save_in_mysql(save_dict):

    create_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    sql = """INSERT INTO dingding_all_info_spider(companyName,legalPerson,registerDate,address,registerCapital,staffSize,tags,bizStatus,industry,opScope,business_capacit,innovation,litigation_risk,operational_risk,shareholders,manager_list,entBrief,ocid,phoneList,emailList,mobile_no,management_info,company_report,change_infor,foreign_investment,branch,core_team,property,company_development,business_info,legal_risk,management_risk,create_time)
      VALUES (%s, %s , %s, %s, %s, %s, %s, %s, %s,%s, %s , %s, %s, %s, %s, %s, %s, %s, %s,%s, %s , %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""  # 插入数据库的SQL语句
    cursor.execute(sql,
                   (save_dict['companyName'],save_dict['legalPerson'],save_dict['registerDate'],save_dict['address'],save_dict['registerCapital'],save_dict['staffSize'],save_dict['tags'],save_dict['bizStatus'],save_dict['industry'],save_dict['opScope'],save_dict['business_capacit'],save_dict['innovation'],save_dict['litigation_risk'],save_dict['operational_risk'],save_dict['shareholders'],save_dict['manager_list'],save_dict['entBrief'],save_dict['ocid'],save_dict['phoneList'],save_dict['emailList'],save_dict['mobile_no'],save_dict['management_info'],save_dict['company_report'],save_dict['change_infor'],save_dict['foreign_investment'],save_dict['branch'],save_dict['core_team'],save_dict['property'],save_dict['company_development'],save_dict['business_info'],save_dict['legal_risk'],save_dict['management_risk'],create_time))

    print('入库成功')
    db.commit()
    db.rollback()
    # db.close()